#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 110;

int n, m; // 物品个数和背包容量
int v[N], w[N];
int e[N], ne[N], h[N], idx;
int dp[N][N]; // 以i为根节点，j为容量的最大收益值

void add(int a, int b)
{
    e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}

// 分组背包问题
void dfs(int u)
{
    // 1. 循环物品组
    for (int i = h[u]; i != -1; i = ne[i])
    {
        int son = e[i];
        dfs(e[i]);
        // 2. 循环背包体积
        for (int j = m - v[u]; j >= 0; j -- )
            // 3. 循环物品决策
            for (int k = 0; k <= j; k ++ )
                dp[u][j] = max(dp[u][j], dp[u][j - k] + dp[son][k]);
    }
    
    // 添加物品u
    for (int i = m; i >= v[u]; i -- ) 
        dp[u][i] = dp[u][i - v[u]] + w[u];
    // 清空剩余的部分
    for (int i = 0; i < v[u]; i ++ )
        dp[u][i] = 0;
}

int main()
{
    memset(h, -1, sizeof h);
    cin >> n >> m;
    
    int root;
    for (int i = 1; i <= n; i ++ )
    {
        int c;
        cin >> v[i] >> w[i] >> c;
        if (c == -1) root = i;
        else add(c, i);
    }
    
    dfs(root);
    
    cout << dp[root][m] << endl;
    
    return 0;
}
